package com.ie.service.impl;

import com.ie.common.http.Result;
import com.ie.entity.shouchang;
import com.ie.mapper.shouchangMapper;
import com.ie.service.shouchangService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class shouchangServiceImpl implements shouchangService {
    @Resource
    private shouchangMapper shouchangMapper;

    @Override
    public Result findShouchang(String userid) {

        return Result.build(shouchangMapper.findShouchang(userid),1, "");
    }

    @Override
    public Result addShouchang(String userid, String cId) {
        System.out.println("============="+userid+"======================"+ cId+"=============");
        shouchang shouchangz = shouchangMapper.findShouchangz(userid, cId);
        System.out.println(shouchangz);
        if (shouchangz== null){
            System.out.println("==========================");
            shouchangMapper.addShouchang(userid, cId);
            shouchangMapper.jia( cId);
            return Result.build(null,1, "收藏成功");
        }else{
            shouchangMapper.deleteShouchang(userid, cId);
            shouchangMapper.jian(cId);
            return Result.build(null,0, "取消收藏");
        }



    }
}
